<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue-2.4.0.js"></script>
    <script src="lib/vue-router-3.0.1.js"></script>
    <style>
        .myactive{
            background-color: red;
        }
    </style>
</head>
<body>
<div id="app">
    <router-link to="/login">登录</router-link>
    <router-link to="/register">注册</router-link>
    <router-view></router-view>
</div>
<script>
    var login={
        template:'<h3>登录子组件</h3>'
    }
    var register={
        template:'<h3>注册子组件</h3>'
    }
    var router=new VueRouter({
        // 路由规则数组
        routes:[
            {path:'/',redirect:'/login'},
            {path:'/login',component:login},
            {path:'/register',component:register},
        ],
        linkActiveClass: 'myactive'
    })
    var vm=new Vue({
        el:"#app",
        data:{

        },
        methods:{

        },
        router,
        watch:{
            '$route.path':function (newVal,oldVal) {
                console.log(newVal+'----'+oldVal)
                if (newVal==='/login'){
                    alert('欢迎进入登录界面')
                }else if(newVal==='/register'){
                    alert('欢迎进入注册界面')
                }
            }
        }
    })
</script>
</body>
</html>